import request from '@/utils/request'

// 查询角色列表
export function listRole(query = {}) {
  query.hasOwnProperty('curPage') || (query.curPage = 1)
  query.hasOwnProperty('pageSize') || (query.pageSize = 500)
  return request({
    url: '/role/query/page',
    method: 'get',
    params: query
  })
  /* return new Promise(resolve => {
    resolve({
      'total': 2,
      'rows': [
        {
          'createBy': null,
          'createTime': '2024-06-30 11:27:15',
          'updateBy': null,
          'updateTime': null,
          'remark': '超级管理员',
          'roleId': 1,
          'roleName': '超级管理员',
          'roleKey': 'admin',
          'roleSort': 1,
          'dataScope': '1',
          'menuCheckStrictly': true,
          'deptCheckStrictly': true,
          'status': '0',
          'delFlag': '0',
          'flag': false,
          'menuIds': null,
          'deptIds': null,
          'permissions': null,
          'admin': true
        },
        {
          'createBy': null,
          'createTime': '2024-06-30 11:27:15',
          'updateBy': null,
          'updateTime': null,
          'remark': '普通角色',
          'roleId': 2,
          'roleName': '普通角色',
          'roleKey': 'common',
          'roleSort': 2,
          'dataScope': '2',
          'menuCheckStrictly': true,
          'deptCheckStrictly': true,
          'status': '0',
          'delFlag': '0',
          'flag': false,
          'menuIds': null,
          'deptIds': null,
          'permissions': null,
          'admin': false
        }
      ],
      'code': 200,
      'msg': '查询成功'
    })
  }) */
}

// 查询角色详细
export function getRole(roleId) {
  return request({
    url: '/system/role/' + roleId,
    method: 'get'
  })
}

// 新增角色
export function addRole(data) {
  return request({
    url: '/role/add',
    method: 'post',
    data: data
  })
}

// 修改角色
export function updateRole(data) {
  return request({
    url: '/system/role',
    method: 'put',
    data: data
  })
}

// 角色数据权限
export function dataScope(data) {
  return request({
    url: '/system/role/dataScope',
    method: 'put',
    data: data
  })
}

// 角色状态修改
export function changeRoleStatus(roleId, status) {
  const data = {
    roleId,
    status
  }
  return request({
    url: '/system/role/changeStatus',
    method: 'put',
    data: data
  })
}

// 删除角色
export function delRole(roleId) {
  return request({
    url: '/role/delete',
    method: 'delete',
    data: roleId
  })
}

// 查询角色已授权用户列表
export function allocatedUserList(query) {
  return request({
    url: '/system/role/authUser/allocatedList',
    method: 'get',
    params: query
  })
}

// 查询角色未授权用户列表
export function unallocatedUserList(query) {
  return request({
    url: '/system/role/authUser/unallocatedList',
    method: 'get',
    params: query
  })
}

// 取消用户授权角色
export function authUserCancel(data) {
  return request({
    url: '/system/role/authUser/cancel',
    method: 'put',
    data: data
  })
}

// 批量取消用户授权角色
export function authUserCancelAll(data) {
  return request({
    url: '/system/role/authUser/cancelAll',
    method: 'put',
    params: data
  })
}

// 授权用户选择
export function authUserSelectAll(data) {
  return request({
    url: '/system/role/authUser/selectAll',
    method: 'put',
    params: data
  })
}

// 根据角色ID查询部门树结构
export function deptTreeSelect(roleId) {
  return request({
    url: '/role/query/department/by/role',
    method: 'get',
    params: { roleId, typeCollection: 1 }
  })
}

// 查询部门
export function deptList(query) {
  return request({
    url: '/department/query/list/condition',
    method: 'get',
    params: query
  })
}

// 为角色添加部门权限
export function roleAddDept(data) {
  return request({
    url: '/role/add/department',
    method: 'post',
    data
  })
}

// 为角色添加菜单权限
export function roleAddMenu(data) {
  return request({
    url: '/role/add/menu',
    method: 'post',
    data
  })
}

//查询角色菜单权限
export function getRoleMenuList(params) {
  return request({
    url: '/role/query/menu',
    method: 'get',
    params
  })
}
